<?php 
/**
 * This file is part of DomFg.
 * 
 * DomFg is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * DomFg is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with DomFg.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * @link http://inditel.ee/
 * @copyright 2007-2009 Inditel Meedia OÜ
 * @author Oliver Leisalu <oliver@inditel.ee>
 */

/**
* @author Oliver Leisalu, Inditel Meedia
* @package DomFg
*/
abstract class DomFgInput extends DomFgComponent {

	protected $name;
	
	/**
	* This property is rendered differently. It will add type=title cell before input cell! So if you add one input cell with title then actually two cells are added. This will become an issue on table layout!
	* @var String
	*/
	protected $title;
	
	protected $textBefore;
	
	protected $textAfter;
	
	protected $onClick;
	
	protected $onChange;
	
	protected $onFocus;
	
	protected $onBlur;
	
	protected $disabled = false;
	
	public function __construct( $name = NULL ) {
		$this->name($name);
	}

	public function name( $name ) {
		if( $this->name !== NULL ) DomFgPost::unregisterInput( $this->name);
		$this->name = $name;
		if( $name != NULL ) DomFgPost::registerInput( $this );	
		return $this;
	}
	
	public function title( $title ) {
		$this->title = $title;
		return $this;
	}
	
	public function textBefore( $textBefore ) {
		$this->textBefore = $textBefore;
		return $this;
	}
	
	public function textAfter( $textAfter ) {
		$this->textAfter = $textAfter;
		return $this;
	}
	
	public function onClick( $onClick ) {
		$this->onClick = $onClick;
		return $this;
	}
	
	public function onChange( $onChange ) {
		$this->onChange = $onChange;
		return $this;
	}
	
	public function onFocus( $onFocus ) {
		$this->onFocus = $onFocus;
		return $this;
	}
	
	public function onBlur( $onBlur ) {
		$this->onBlur = $onBlur;
		return $this;
	}
	
	public function disabled( $disabled ) {
		$this->disabled = (bool)$disabled;
	}
	
	public function getEventsHtml() {
		$events = '';
		if( $this->onFocus ) {
			$events.= 'onfocus="'.$this->onFocus.'"';
		}
		if( $this->onBlur ) {
			$events.= 'onblur="'.$this->onBlur.'"';
		}
		if( $this->onchange ) {
			$events.= 'onchange="'.$this->onChange.'"';
		}
		if( $this->onClick ) {
			$events.= 'onclick="'.$this->onClick.'"';
		}
		return $events;
	}
	
	abstract public static function parsePost( $name, &$value );

}
?>